package com.ruoyi.app.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.app.domain.AppDonations;
import com.ruoyi.app.service.IAppDonationsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 捐赠记录管理Controller
 * 
 * @author ruoyi
 * @date 2025-11-06
 */
@RestController
@RequestMapping("/app/donations/test")
public class AppDonationsController extends BaseController
{
    @Autowired
    private IAppDonationsService appDonationsService;

    /**
     * 查询捐赠记录管理列表
     */
    @PreAuthorize("@ss.hasPermi('app:donations:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppDonations appDonations)
    {
        startPage();
        List<AppDonations> list = appDonationsService.selectAppDonationsList(appDonations);
        return getDataTable(list);
    }

    /**
     * 导出捐赠记录管理列表
     */
    @PreAuthorize("@ss.hasPermi('app:donations:export')")
    @Log(title = "捐赠记录管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppDonations appDonations)
    {
        List<AppDonations> list = appDonationsService.selectAppDonationsList(appDonations);
        ExcelUtil<AppDonations> util = new ExcelUtil<AppDonations>(AppDonations.class);
        util.exportExcel(response, list, "捐赠记录管理数据");
    }

    /**
     * 获取捐赠记录管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:donations:query')")
    @GetMapping(value = "/{donationId}")
    public AjaxResult getInfo(@PathVariable("donationId") Long donationId)
    {
        return success(appDonationsService.selectAppDonationsByDonationId(donationId));
    }

    /**
     * 新增捐赠记录管理
     */
    @PreAuthorize("@ss.hasPermi('app:donations:add')")
    @Log(title = "捐赠记录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppDonations appDonations)
    {
        return toAjax(appDonationsService.insertAppDonations(appDonations));
    }

    /**
     * 修改捐赠记录管理
     */
    @PreAuthorize("@ss.hasPermi('app:donations:edit')")
    @Log(title = "捐赠记录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppDonations appDonations)
    {
        return toAjax(appDonationsService.updateAppDonations(appDonations));
    }

    /**
     * 删除捐赠记录管理
     */
    @PreAuthorize("@ss.hasPermi('app:donations:remove')")
    @Log(title = "捐赠记录管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{donationIds}")
    public AjaxResult remove(@PathVariable Long[] donationIds)
    {
        return toAjax(appDonationsService.deleteAppDonationsByDonationIds(donationIds));
    }
}
